package until

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"crypto/rand"
    "math"
	"math/big"
)

func HTML(c *gin.Context,path string,data gin.H){
	for k, v := range c.Keys {
		data[k]=v
	}
	c.HTML(http.StatusOK,path,data)
}
func Success(c *gin.Context,data interface{}){
	c.JSON(http.StatusOK,gin.H{"status":gin.H{"errorCode":0,"msg":"成功"},"data":data})
}
func Fail(c *gin.Context,code int,msg string){
	c.JSON(http.StatusOK,gin.H{"status":gin.H{"errorCode":code,"msg":msg}})
}

// 生成区间[-m, n]的安全随机数
func RangeRand(min, max int64) int64 {
    if min > max {
        panic("the min is greater than max!")
    }
  
    if min < 0 {
        f64Min := math.Abs(float64(min))
        i64Min := int64(f64Min)
        result, _ := rand.Int(rand.Reader, big.NewInt(max + 1 + i64Min))
  
        return result.Int64() - i64Min
    } else {
        result, _ := rand.Int(rand.Reader, big.NewInt(max-min+1))
        return min + result.Int64()
	}
}